<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>${r'${sysName}'}</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${r'${resRoot}'}/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="${r'${resRoot}'}/layui/admin/admin.css" media="all" />
	<link id="layuicss-layer" rel="stylesheet" href="${r'${resRoot}'}/layui/css/modules/layer/default/layer.css" media="all">
</head>
<body>
<div class="layui-fluid">   
          <div class="layui-card">
          <div class="layui-form layui-card-header layuiadmin-card-header-auto"> 
 
<form class="layui-form" action="#" style="margin-top: 20px;margin-bottom:50px;" lay-filter="dataForm"  >
<input type="hidden" id="id" name="id"  >
  <#list table.fields as field>
  <#if field.htmlType?? && field.htmlType=="1">
  <!-- 图片 -->
  	<div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">${field.comment!}</label>
      <div class="layui-input-inline">
      <div class="site-demo-upload">
		  <img id="${field.propertyName}_img" imgName="" src="" style="max-width:200px;max-height:200px;">
		  <input type="hidden" name="${field.propertyName}" id="${field.propertyName}" value="" >
		  <button type="button" class="layui-btn" id="test${field_index}">
		  <i class="layui-icon"></i>上传${field.comment!}
		</button>
		</div>
      </div>
    </div>
  </div>
  <#elseif field.htmlType?? && field.htmlType=="2">
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">${field.comment!}</label>
      <div class="layui-input-inline">
      <div class="site-demo-upload" id="${field.propertyName}_div" >
		  <img id="${field.propertyName}_img" imgName="" src="" style="max-width:200px;max-height:200px;">
		  <input type="hidden" name="${field.propertyName}" id="${field.propertyName}"  >
		  <button type="button" class="layui-btn" id="test${field_index}">
		  <i class="layui-icon"></i>上传${field.comment!}
		</button>
		</div>
      </div>
    </div>
  </div>
  <#elseif field.htmlType?? && field.htmlType=="5">
  <div class="layui-form-item">
    <label class="layui-form-label">${field.comment!}</label>
    <div class="layui-input-block">
  	<textarea name="${field.propertyName}" id="${field.propertyName}" rows="20" cols="2"></textarea>
    </div>
  </div>
  
  <#elseif field.htmlType?? && field.htmlType=="3">
  <div class="layui-form-item">
    <label class="layui-form-label">${field.comment!}</label>
    <div class="layui-input-inline">
    <select name="${field.propertyName}" id="${field.propertyName}" lay-filter="${field.propertyName}Change" <#if field.notNull?? && field.notNull!="1">lay-verify="required" lay-reqtext="请选择${field.comment!}"</#if>  >
        <option value="">请选择${field.comment!}</option>
      </select>
    </div>
  </div>
  <#elseif field.htmlType?? && field.htmlType=="0">
  <div class="layui-form-item">
    <label class="layui-form-label">${field.comment!}</label>
    <div class="layui-input-inline">
    	<#if field.propertyType=="LocalDateTime">
	      <input type="text" class="layui-input" id="${field.propertyName}"  onClick="WdatePicker({startDate:'%y-%M-%d 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true});" placeholder="yyyy-MM-dd" value="" lay-verify="<#if field.notNull?? && field.notNull!="1">required|</#if>date" >
	    <#elseif field.propertyType=="Long" || field.propertyType=="Double" || field.propertyType=="Integer">
	      <input type="number" name="${field.propertyName}" id="${field.propertyName}" value=""  autocomplete="off" placeholder="请输入${field.comment!}" class="layui-input" <#if field.notNull?? && field.notNull!="1">lay-verify="required|number" lay-reqtext="请输入${field.comment!}"</#if> >
	      <#else>
	      <input type="text" name="${field.propertyName}" id="${field.propertyName}" value=""  autocomplete="off" placeholder="请输入${field.comment!}" class="layui-input" <#if field.notNull?? && field.notNull!="1">lay-verify="required" lay-reqtext="请输入${field.comment!}"</#if> >
    	</#if>
    </div>
    <div class="layui-form-mid layui-word-aux">请输入${field.comment!}</div>
  </div>
  <#elseif field.htmlType?? && field.htmlType=="4">
<div class="layui-form-item">
    <label class="layui-form-label">${field.comment!}</label>
    <div class="layui-input-block">
  	<textarea name="${field.propertyName}" id="${field.propertyName}" placeholder="${field.comment!}" class="layui-textarea" ></textarea>
    </div>
  </div>
  <#elseif field.htmlType?? && field.htmlType=="7">
<div class="layui-form-item">
    <label class="layui-form-label">${field.comment!}</label>
    <div class="layui-input-inline">
    	<input type="text" class="layui-input" id="${field.propertyName}" name="${field.propertyName}"  onClick="WdatePicker({startDate:'%y-%M-%d 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true});" placeholder="yyyy-MM-dd HH:mm:ss" value="" lay-verify="<#if field.notNull?? && field.notNull!="1">required|</#if>date" >
    </div>
    <div class="layui-form-mid layui-word-aux">请选择${field.comment!}</div>
  </div>
  <#elseif field.htmlType?? && field.htmlType=="6">
<div class="layui-form-item">
    <label class="layui-form-label">${field.comment!}</label>
    <div class="layui-input-inline">
    	<input type="text" class="layui-input" id="${field.propertyName}" name="${field.propertyName}"  onClick="WdatePicker({startDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true});" placeholder="yyyy-MM-dd" value="" lay-verify="<#if field.notNull?? && field.notNull!="1">required|</#if>date" >
    </div>
    <div class="layui-form-mid layui-word-aux">请选择${field.comment!}</div>
  </div>
  <#elseif field.htmlType?? && field.htmlType=="8">
<div class="layui-form-item">
    <label class="layui-form-label">${field.comment!}</label>
    <div class="layui-input-inline">
    <!-- 当字典值大于10后，请更换字典的value否则 contains 01 时10、11...会选中 -->
    	<#if field.dictValue?? && field.dictValue!="">
			${r'<#list dictMap['}'${field.dictValue}'${r']?keys as key>'}
    			<input type="checkbox" name="${field.propertyName}" value="${r'${key}'}" title="${r'${dictMap['}'${field.dictValue}'${r'][key]}'}" ${r'<#if '}${table.entityPath}.${field.propertyName}?? && ${table.entityPath}.${field.propertyName}${r'?contains(key)>checked</#if>'} >
			${r'</#list>'}
		</#if>
    </div>
    <div class="layui-form-mid layui-word-aux">请选择${field.comment!}</div>
  </div>
  <#elseif field.htmlType?? && field.htmlType=="9">
<input type="hidden" id="${field.propertyName}" name="${field.propertyName}" value="" >
 </#if>

  </#list>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" id=""  lay-submit="" lay-filter="dataSaveSubmit"  type="button">立即提交</button>
      <button type="button" class="layui-btn layui-btn-primary" onclick="backList();" >返回</button>
    </div>
  </div>
</form>
</div>
  </div>
  </div>
${r'<#include "/page/footer.html">'}
<script>
var id = "${r'${id!}'}";
$(function(){
<#list table.fields as field>
<#if field.htmlType?? && field.htmlType=="3">
<#if field.dictValue??>
setDictSelect("${field.propertyName}", "${field.dictValue!}", "");
</#if>
</#if>
</#list>


$(function(){
	var dataTmp = getDataById(id, "${r'${base}'}/sys/${table.entityPath?substring(0, table.entityPath?length - 3)}/get/" + id)
	<#list table.fields as field>
	  <#if field.htmlType?? && field.htmlType=="1">
	  $("#${field.propertyName}_img").attr(src, dataTmp.${field.propertyName});
	  $("#${field.propertyName}_img").attr(imgName, dataTmp.${field.propertyName});
	  <#elseif field.htmlType?? && field.htmlType=="2">
	  $("#${field.propertyName}_img").attr(src, dataTmp.${field.propertyName});
	  $("#${field.propertyName}_img").attr(imgName, dataTmp.${field.propertyName});
	  </#if>
	  </#list>
})
});
function backList() {
	parent.layer.closeAll("iframe");
    //刷新父页面
    parent.location.reload();
}

function removeImg(id) {
	layer.confirm('您是确认删除/查看该图片吗？', {
		  btn: ['确认','查看'] //按钮
		}, function(){
			$("#" + id).attr("src", "");
			layer.msg('已删除！');
		}, function(){
			window.open($("#" + id).attr("src"));
		  //layer.msg('已取消！');
		});
}
layui.use(['form', 'layedit', 'laydate', 'upload'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
  
  
  var upload = layui.upload;
  <#list table.fields as field>
  <#if field.htmlType?? && field.htmlType=="1">
		var uploadInst${field_index} = upload.render({
		    elem: '#test${field_index}' //绑定元素
		    ,url: '${r'${base}'}/uploadImage' //上传接口
		    ,done: function(res){
		    if(res != "") {
	    		var obj = res;
				$("#${field.propertyName}_img").attr("src", obj.imageUrl);
				$("#${field.propertyName}_img").attr("imgName", obj.imageUrl);
	    		$("#${field.propertyName}").val(obj.dataId);
			}
		      //上传完毕回调
		    }
		    ,error: function(){
		      //请求异常回调
		    }
		  });
		  <#elseif field.htmlType?? && field.htmlType=="2">
		var uploadInst${field_index} = upload.render({
		    elem: '#test${field_index}' //绑定元素
		    ,url: '${r'${base}'}/uploadImage' //上传接口
		    ,done: function(res){
		    if(res != "") {
	    		var obj = res;
	    		$("#${field.propertyName}_div").prepend('< img id="${field.propertyName}_img" imgName="' + obj.imageUrl + '" src="${r'${picUrlHost}'}' + obj.imageUrl +'" style="max-width:200px;max-height:200px;">'      //上传完毕回调
	    		var value = $("#${field.propertyName}").val();
	    		if(value) {
	    			value = value + "," + obj.dataId;
	    		} else {
	    			value = obj.dataId;
	    		}
	    		$("#${field.propertyName}").val(value);
		    }
		    ,error: function(){
		      //请求异常回调
		    }
		  });
		<#elseif field.htmlType?? && field.htmlType=="5">
		  var ${field.propertyName} = CKEDITOR.replace( '${field.propertyName}' );
		    CKFinder.setupCKEditor(${field.propertyName}, '${r'${base}'}/ckfinder/');
  </#if>
  </#list>
  
  // 页面验证，及自定义验证规则 样例 表单验证参考  https://www.layui.com/demo/form.html
  form.verify({
    title: function(value){
      if(value.length == 0){
        return '参数不能为空';
      }
    }
    ,pass: [/(.+){6,12}$/, '密码必须6到12位']
    ,content: function(value){
      layedit.sync(editIndex);
    }
  });
  
  
  form.on('submit(dataSaveSubmit)', function(data){
      var index = layer.msg('加载中...',{icon: 16,time:false,shade:0.8});
      delete data.field.file;
      $.ajax({
			url : "${r'${base}'}/sys/${table.entityPath?substring(0, table.entityPath?length - 3)}/save",
			contentType : "application/json",
         	dataType : 'json',
			data : JSON.stringify(data.field),
          	type:'post',
			async : true,
			success : function(data) {
				layer.close(index);
				console.log(data)
				if(data.code == 1) {
						layer.msg('保存成功！', {
						  icon: 1,
						  time: 2000 //2秒关闭（如果不配置，默认是3秒）
						}, function(){
							backList();
						});   
					} else {
						layer.msg(data.msg); 
					}
			}
		}); 
    });
  
});

layui.use('upload', function(){
	  
});  
</script>
</body>
</html>